import { expect } from 'chai';
import getRandomItem from '../src/getRandomItem.js';

describe('getRandomItem', function() {
    it('should return null for empty arguments', function() {
        expect(getRandomItem()).to.be.eql(null);
    });

    it('should return the only item for single element', function() {
        expect(getRandomItem([1])).to.be.eql(1);
    });

    it('should return the random item for multiple elements', function() {
        const arr = [1, 2, 3, 4];
        const item = getRandomItem(arr);
        expect(arr).to.include(item);
    });

    it('should not be the same item', function() {
        function getDiff() {
            const arr = [1, 2, 3, 4];
            const a = getRandomItem(arr);
            const b = getRandomItem(arr);
            return Math.abs(a - b);
        }

        const result = getDiff() + getDiff() + getDiff();
        expect(result).to.be.greaterThan(0);
    });
});
